/** vue 混入 */
let mixin = {
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      size: [10, 20, 50, 100]
    }
  },
  computed: {
    pages() {
      return this.total ? Math.ceil(this.total / this.pageSize) : 0
    }
  },
  watch: {
    pageSize(newPageSize) {
      if (newPageSize * this.currentPage > total) {
        this.currentPage = Math.ceil(this.total / this.pageSize)
      }
      this.initTable({ currentPage: this.currentPage, pageSize: newPageSize })
    },
    currentPage(newCurrentPage) {
      this.initTable({ currentPage: newCurrentPage, pageSize: this.pageSize })
    }
  },
  created() {
    this.initTable({ currentPage: this.currentPage, pageSize: this.pageSize })
  },
  methods: {
    /** 上一页 */
    onPrePage(currentPage) {
      if (currentPage > 1) {
        this.currentPage--
      }
    },

    /** 下一页 */
    onNextPage(currentPage) {
      if (currentPage < this.pages) {
        this.currentPage++
      }
    }
  }
}

let exported = true // false 禁用打印
/** 控制打印 */
function printInfo(...args) {
  return exported && console.info(...args)
}
